<?php echo $this->doctype(); ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Privilege</title>
<?php
	echo $this->headLink()->appendStylesheet($this->base."../css/privilege.css");
?>
<script language="javascript">
	function changeUrl(name)
	{
		window.location.href = "/Apprentice_CMS/public/admin/privilege/list?modulename="+name;
	}
	function privilegeChangeUrl(actName,action,id,name){
		window.location.href = "/Apprentice_CMS/public/admin/privilege/"+actName+"?action="+action+"&id="+id+"&module="+name;
	}
</script>
</head>	
<body>
	<br />
<div class="leftFrame">
<?php		
	//hien thi danh sach cac module (danh sach nay co the click duoc):
	if($this->moduleResult){
		while ($rows = $this->moduleResult->fetch()){			
			$moduleName = $rows['module_name'];
			echo "<div id='ModuleItem' onclick='changeUrl(\"".$moduleName."\")'>";					
			echo "<div id='module'>$moduleName</div>";
			echo "</div>";	
		}
	}
?>
</div>
<div class='rightFrame'>
<?php
	$controllerArray = $this->conArray;
	$num = count($controllerArray);
	//Hien thi danh sach cac quyen + cac button Add va Delete tuong ung dzoi module da click:	
	if($this->priResult){
		while($rows = $this->priResult->fetch()){
			$isDeleted = $rows['isDeleted'];
			if($isDeleted == 0){
				$btnName = "[ Delete ]";
				$action = "delete";
			}
			else{
				$btnName = "[ &nbsp Add &nbsp ]";
				$action = "add";
			}
			$id = (string)$rows['privilege_id'];	
			$module = (string)$rows['module_name'];
			$description = 	$rows['description'];
			$controller = $rows['controller_name'];
			
			for($i=0;$i<$num;$i++){
				if($controller == $controllerArray[$i]){
					$controllerArray[$i] = null;
					echo "<br>";
					echo "<div class='controllerName'>Manage $controller:</div>";	
				}						
			}			
			echo "<div id='privilegeItem' onclick='privilegeChangeUrl(\"".$action."\",\"".$action."\",\"".$id."\",\"".$module."\")'><div id='description'><li>$description";
			echo "<a class='bt'>$btnName</a></li></div></div>";			
		}
	}
?>
</div>
<form name ="frm" method="post">
<input type="submit" name="back" class="btSubmit" value="Back"></input>
</form>
</body>
</html>